<template>
  <a-form-model :model="form" ref="ruleForm" :rules="rules" :label-col="{ span: 5 }" :wrapper-col="{ span: 17 }" >
    <a-form-model-item label="对象" prop="personName">
      <a-input :disabled="true" v-model="form.personName" placeholder="请输入" />
    </a-form-model-item>
    <a-form-model-item label="身份证" prop="identityCard">
      <a-input :disabled="true" v-model="form.identityCard" placeholder="请输入" />
    </a-form-model-item>
    <a-form-model-item label="现居住地" prop="currentAddress">
      <a-input :disabled="!footerBool" v-model="form.currentAddress" placeholder="请输入" />
    </a-form-model-item>
    <a-form-model-item label="户籍所在地" prop="householdAddress">
      <a-input :disabled="!footerBool" v-model="form.householdAddress" placeholder="请输入" />
    </a-form-model-item>
    <a-form-model-item label="犯罪经历" prop="criminalExperience">
      <a-textarea :disabled="!footerBool" v-model="form.criminalExperience" placeholder="请输入" :auto-size="{ minRows: 2, maxRows: 6 }" />
    </a-form-model-item>
    <a-form-model-item label="解除意见" prop="cancellationOpinion">
      <a-textarea :disabled="!footerBool" v-model="form.cancellationOpinion" placeholder="请输入" :auto-size="{ minRows: 2, maxRows: 6 }" />
    </a-form-model-item>
    <a-form-model-item label="附件上传" prop="file">
      <UploadAvatar ref="uploadAvatar" :avatarType="1" :imgURL="form.file" :disabled="!footerBool" @getAvatar="getAvatar" />
    </a-form-model-item>
    <a-form-model-item label="抄送人" prop="userList" ref="userList">
      <ScopeApplication ref="SelectIndex" :checkedDataType="[1]" :disabled="!footerBool" :isModal="true" @getRangeInfo="getRangeInfo" />
    </a-form-model-item>
  </a-form-model>
</template>

<script>
  import { mapState } from 'vuex'
  import UploadAvatar from '@/components/base/upload/UploadAvatar'
  import ScopeApplication from "@/components/business/ScopeApplication"
  import {recoveryNoticeDetail} from "@/api/personnelFiles"
  export default {
    props: ['formData','footerBool','applyKey'],
    components: {
      UploadAvatar, ScopeApplication
    },
    data() {
      return {
        form: {},
        rules: {
          personName: [
            { required: true, message: "请输入", trigger: "change" },
          ],
          identityCard: [
            { required: true, message: "请输入", trigger: "change" },
          ],
          currentAddress: [
            { required: true, message: "请输入", trigger: "change" },
          ],
          householdAddress: [
            { required: true, message: "请输入", trigger: "change" },
          ],
          criminalExperience: [
            { required: true, message: "请输入", trigger: "change" },
          ],
          cancellationOpinion: [
            { required: true, message: "请输入", trigger: "change" },
          ],
          file: [
            { required: true, message: "请上传附件", trigger: "change" },
          ],
        },
      }
    },
    watch: {
      formData: {
        immediate: true,
        handler(val) {
          // console.log(val)
          this.form = Object.assign({}, val)
        },
      },
      applyKey: {
        immediate: true,
        handler(val) {
          if(val) this.geRecoveryNoticeDetail(val)
        },
      }
    },
    methods: {
      // 获取康复通知书详情
      async geRecoveryNoticeDetail(id) {
        let res = await recoveryNoticeDetail(id)
        if(res.status==200)  {
          let data = res.data
          data.file = data.fileId
          this.form = Object.assign({...this.form, ...data})
        }
      },
      // 获取适用范围值
      getRangeInfo(data) {
        this.form.userList = data
      },
      // 获取头像值
      getAvatar(data) {
        console.log(data)
        if(data.length>0) {
          this.form.file = data.map((obj,index)=>{
            return obj.data;
          }).join(',')
        }
        console.log(this.form)
      }
    },
  }
</script>

<style lang="less">
</style>
